package com.taptech.doufu.ui.adapter;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.taptech.doufu.util.TTLog;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TTBaseAdapter extends BaseAdapter {

	protected View mHeaderView;
	protected boolean mHasHeaderView;

	public SparseArray<Drawable> mImageDrawables;
	protected boolean mIsScorllStateIdle;

	public int mFirstVisiblePosition;
	public int mLastVisiblePosition;

	public final int EXTRA_TOP_NUM = 20;
	public final int EXTRA_BOTTOM_NUM = 20;
	public Map<Integer, Map<String, ImageView>> cacheImages;

	public SparseArray<Set<String>> cacheUrls;
	public SparseArray<View> cacheViews;

	public TTBaseAdapter() {
		this.mHasHeaderView = false;
		this.mImageDrawables = new SparseArray<Drawable>(30);
		this.cacheImages = new HashMap<Integer, Map<String, ImageView>>();
		cacheViews = new SparseArray<View>();
		this.mIsScorllStateIdle = true;
		this.mFirstVisiblePosition = AdapterView.INVALID_POSITION;
		this.mLastVisiblePosition = AdapterView.INVALID_POSITION;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}

	public void setScrollStateIdle(boolean idle) {
		this.mIsScorllStateIdle = idle;
	}

	public boolean getScorllStateIdle() {
		return this.mIsScorllStateIdle;
	}

	public int getDataIndex(int position) {
		position--;
		if (mHasHeaderView) {
			position--;
		}

		return position;
	}

	 
 

	public void recycleAllBitmaps() {

		if (mImageDrawables == null) {
			return;
		}

		for (int i = 0; i < mImageDrawables.size(); i++) {

			if ((BitmapDrawable) mImageDrawables.get(i) == null) {
				continue;
			}

			Bitmap bitmap = ((BitmapDrawable) mImageDrawables.get(i))
					.getBitmap();

			if (bitmap != null) {

				TTLog.e("recycleBitmap", "recycle position:" + i);

				mImageDrawables.remove(i);
				bitmap.recycle();
				bitmap = null;
				System.gc();
			}
		}

	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}
	
	public void clear()
	{
		
	}

}
